/*
 * File: deadband_comp.c
 *
 * Code generated for Simulink model 'deadband_comp'.
 *
 * Model version                  : 1.149
 * Simulink Coder version         : 24.1 (R2024a) 19-Nov-2023
 * C/C++ source code generated on : Mon Jun 16 13:50:03 2025
 *
 * Target selection: ert.tlc
 * Embedded hardware selection: ARM Compatible->ARM Cortex
 * Code generation objectives:
 *    1. Execution efficiency
 *    2. Traceability
 * Validation result: Not run
 */

#include "deadband_comp.h"
#include "rtwtypes.h"

/* Macros for accessing real-time model data structure */
#ifndef rtmGetErrorStatus
#define rtmGetErrorStatus(rtm)         (*((rtm)->errorStatus))
#endif

#ifndef rtmSetErrorStatus
#define rtmSetErrorStatus(rtm, val)    (*((rtm)->errorStatus) = (val))
#endif

#ifndef rtmGetErrorStatusPointer
#define rtmGetErrorStatusPointer(rtm)  (rtm)->errorStatus
#endif

#ifndef rtmSetErrorStatusPointer
#define rtmSetErrorStatusPointer(rtm, val) ((rtm)->errorStatus = (val))
#endif

/* Output and update for atomic system: '<Root>/deadband_comp' */
void deadband_comp_deadband_comp(const real32_T *rtu_u_tar, const real32_T
    *rtu_i_now, const real32_T *rtu_i_noise, const real32_T *rtu_comp_du,
    real32_T *rty_u_tar_comp)
{
    /* MATLAB Function: '<S1>/deadband_comp' */
    /* MATLAB Function 'deadband_comp/deadband_comp': '<S2>:1' */
    /* '<S2>:1:2' if i_noise < 0.00001 */
    if (*rtu_i_noise < 1.0E-5)
    {
        /* '<S2>:1:3' u_tar_comp = single(0); */
        *rty_u_tar_comp = 0.0F;
    }
    else
    {
        real32_T line_range;

        /* '<S2>:1:7' du = single(0); */
        /* '<S2>:1:8' line_range = i_noise * single(2); */
        line_range = *rtu_i_noise * 2.0F;

        /* '<S2>:1:9' k = comp_du / line_range; */
        /* '<S2>:1:12' if i_now <= line_range && i_now >= -line_range */
        if ((*rtu_i_now <= line_range) && (*rtu_i_now >= -line_range))
        {
            /* '<S2>:1:13' du = k * i_now; */
            line_range = *rtu_comp_du / line_range * *rtu_i_now;

            /* '<S2>:1:14' else */
            /* '<S2>:1:15' if i_now > single(0) */
        }
        else if (*rtu_i_now > 0.0F)
        {
            /* '<S2>:1:16' du = comp_du; */
            line_range = *rtu_comp_du;
        }
        else
        {
            /* '<S2>:1:17' else */
            /* '<S2>:1:18' du = -comp_du; */
            line_range = -*rtu_comp_du;
        }

        /* '<S2>:1:22' u_tar_comp = u_tar + du; */
        *rty_u_tar_comp = *rtu_u_tar + line_range;
    }

    /* End of MATLAB Function: '<S1>/deadband_comp' */
}

/* Output and update for referenced model: 'deadband_comp' */
void deadband_compTID0(void)
{
}

/* Output and update for referenced model: 'deadband_comp' */
void deadband_compTID1(const real32_T *rtu_u_tar, const real32_T *rtu_i_now,
                       const real32_T *rtu_i_noise, const real32_T *rtu_comp_du,
                       real32_T *rty_u_tar_comp)
{
    /* Outputs for Atomic SubSystem: '<Root>/deadband_comp' */
    deadband_comp_deadband_comp(rtu_u_tar, rtu_i_now, rtu_i_noise, rtu_comp_du,
        rty_u_tar_comp);

    /* End of Outputs for SubSystem: '<Root>/deadband_comp' */
}

/* Model initialize function */
void deadband_comp_initialize(const char_T **rt_errorStatus,
    deadband_comp_RT_MODEL *const deadband_comp_rt_M)
{
    /* Registration code */

    /* initialize error status */
    rtmSetErrorStatusPointer(deadband_comp_rt_M, rt_errorStatus);
}

/*
 * File trailer for generated code.
 *
 * [EOF]
 */
